<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		
		<link rel="stylesheet" type="text/css" href="../../style.css" />
		
		<script type="text/javascript" src="../../navigation_menu.js"></script>
		<script type="text/javascript" src="../../validation.js"></script>
		
		<script type="text/javascript">
		    var djConfig = {
				isDebug:true,
				parseOnLoad:true,
				usePlainJson:true
		    };
		</script>
		 
		<script type="text/javascript" src="../../dojo/dojo/dojo.js"></script>
		<script type="text/javascript" src="../../dojo/dijit/dijit.js"></script>

		<script type="text/javascript">
    		dojo.require("dijit.form.Button");
    		dojo.require("dojo.rpc.JsonService");    	
    	</script>
		
		<script language="JavaScript" type="text/javascript">
			var makeShipperNoteService = new dojo.rpc.JsonService("MakeShipperNoteService?smd");
			var isBoxAndGoodsPut = false;
			
			//页面加载时的一些操作
			dojo.addOnLoad(load);
			function load() {
				menu_main('../../nav.xml', 'navigation_menu');
				initPage();
			}
			//得到当前日期
			function showDate() {
				var today = new Date();   
				var day = today.getDate();   
				var month = today.getMonth() + 1;   
				var year = today.getFullYear();   
				return year + "-" + month + "-" + day;
			}
			//初始化页面
			function initPage() {
				makeShipperNoteService.getOrderPlanID().addCallback(function (result) {
					document.getElementById("sn_num1").innerHTML = result;
					document.getElementById("sn_num2").innerHTML = result;
				});
				
				var cur_date = showDate();
			
				//上次更改日期为当前日期
				document.getElementById("sn_last_modified_date").innerHTML = cur_date;
				//初始化日期为当前日期
				document.getElementById("sn_init_date").value = cur_date;
	
				makeShipperNoteService.getAllocDetails().addCallback(function (AD) {
					console.dir(AD);
					document.getElementById("shipcom_name").value = AD.commission.shipComInfo.fullTitle;
					document.getElementById("sender").value = AD.commission.sender.name;
					document.getElementById("receiver").value = AD.commission.receiver.name;
					document.getElementById("departure").value = AD.commission.departure;
					document.getElementById("receive_loc").value = AD.commission.receiveLoc;
					document.getElementById("unload_loc").value = AD.commission.destination;
					document.getElementById("destination").value = AD.commission.destination;
					document.getElementById("box_total").value = AD.bigNum + AD.smallNum;
					document.getElementById("goods_type").value = AD.commission.goods.type;
					if (AD.commission.goods.tempUnit != null) {
						document.getElementById("goods_temp").value = AD.commission.goods.temp;
					}
					if (AD.commission.multiShip == true) {
						document.getElementById("multiship").value = "Y";
					} else {
						document.getElementById("multiship").value = "N";
					}
					if (AD.commission.multiSchedule == true) {
						document.getElementById("multischedule").value = "Y";
					} else {
						document.getElementById("multischedule").value = "N";
					}
				});
				makeShipperNoteService.getOrderPlan().addCallback(function (orderPlan) {
					console.dir(orderPlan);
					document.getElementById("ship_schedule").value = orderPlan.shipSchedule.id;
					document.getElementById("ship_name").value = orderPlan.shipSchedule.shipInfo.name;
				});
			}
			//制单
			function make_shipper_note() {
				if (isBoxAndGoodsPut == false) {
					makeShipperNoteService.putBoxAndGoods(document.getElementById("cy_id").value,
							document.getElementById("sn_id").value).addCallback(function () {
								isBoxAndGoodsPut = true;
							});
				}
				var comments;
				//加入数据库
				if (document.getElementById("sn_comments") == null) {
					comments = null;
				} else {
					comments = document.getElementById("sn_comments").value;
				}
				makeShipperNoteService.putShipperNote(document.getElementById("sn_id").value,
						document.getElementById("cy_id").value,
						document.getElementById("sn_init_date").value,
						document.getElementById("sn_date_of_expiry").value,
						comments).addCallback(function (res) {
							alert(res);
							if (res == "添加成功") {
								//跳转到新页面
								window.open("order_box.html");
							}
						});
			}
			//关闭
			function close_shipper_note() {
				window.close();
			}
			//返回
			function go_back() {
				window.opener.focus();
				window.close();
			}
			//显示发货人信息
			function show_sender_info() {
				makeShipperNoteService.getAllocDetails().addCallback(function (AD) {
					console.dir(AD);
					var text = "";
					text = text + "<table border='1'>";
					text = text + "    <tr><th>发货人</th><th>地址</th><th>联系人</th><th>电话</th><th>传真</th><th>邮箱</th></tr>";
					text = text + "    <tr>";
					text = text + "        <td>" + AD.commission.sender.name +"</td>";
					text = text + "        <td>" + AD.commission.sender.addr + "</td>";
					text = text + "        <td>" + AD.commission.sender.customerContact.name + "</td>";
					text = text + "        <td>" + AD.commission.sender.customerContact.OTel + "</td>";
					text = text + "        <td>" + AD.commission.sender.customerContact.fax + "</td>";
					text = text + "        <td>" + AD.commission.sender.customerContact.email + "</td>";
					text = text + "    </tr>";
					text = text + "</table>";
					document.getElementById("show_results").innerHTML = text;
				});
			}
			//显示收货人信息
			function show_receiver_info() {
				makeShipperNoteService.getAllocDetails().addCallback(function (AD) {
					console.dir(AD);
					var text = "";
					text = text + "<table border='1'>";
					text = text + "    <tr><th>收货人</th><th>地址</th><th>联系人</th><th>电话</th><th>传真</th><th>邮箱</th></tr>";
					text = text + "    <tr>";
					text = text + "        <td>" + AD.commission.receiver.name +"</td>";
					text = text + "        <td>" + AD.commission.receiver.addr + "</td>";
					text = text + "        <td>" + AD.commission.receiver.customerContact.name + "</td>";
					text = text + "        <td>" + AD.commission.receiver.customerContact.OTel + "</td>";
					text = text + "        <td>" + AD.commission.receiver.customerContact.fax + "</td>";
					text = text + "        <td>" + AD.commission.receiver.customerContact.email + "</td>";
					text = text + "    </tr>";
					text = text + "</table>";
					document.getElementById("show_results").innerHTML = text;
				});
			}
			//显示通知人信息
			function show_notifier_info() {
				makeShipperNoteService.getAllocDetails().addCallback(function (AD) {
					console.dir(AD);
					var text = "";
					text = text + "<table border='1'>";
					text = text + "    <tr><th>通知人</th><th>地址</th><th>联系人</th><th>电话</th><th>传真</th><th>邮箱</th></tr>";
					text = text + "    <tr>";
					text = text + "        <td>" + AD.commission.notifier.name +"</td>";
					text = text + "        <td>" + AD.commission.notifier.addr + "</td>";
					text = text + "        <td>" + AD.commission.notifier.customerContact.name + "</td>";
					text = text + "        <td>" + AD.commission.notifier.customerContact.OTel + "</td>";
					text = text + "        <td>" + AD.commission.notifier.customerContact.fax + "</td>";
					text = text + "        <td>" + AD.commission.notifier.customerContact.email + "</td>";
					text = text + "    </tr>";
					text = text + "</table>";
					document.getElementById("show_results").innerHTML = text;
				});
			}
			//显示货物信息
			function show_goods_info() {
				if (isBoxAndGoodsPut == false) {
					makeShipperNoteService.putBoxAndGoods(document.getElementById("cy_id").value,
							document.getElementById("sn_id").value).addCallback(function () {
								isBoxAndGoodsPut = true;
								
								show_goods_info_real();
							});
				} else {
					show_goods_info_real();
				}
			}
			function show_goods_info_real() {
				makeShipperNoteService.getBoxAndGoods(document.getElementById("sn_id").value).addCallback(function (BAG) {
					console.dir(BAG);

					var bag = BAG.list;
					var totalBox = 0;
					var totalWeight = 0;
					var totalSize = 0;
					
					var text = "";
					text = text + "<table border='1'>";
					text = text + "    <tr><th>集装箱号</th><th>铅封号</th><th>箱数或件数</th><th>包装种类与货名</th><th>毛重(公斤)</th><th>尺码(立方米)</th></tr>";
					for (var i in bag) {
						text = text + "    <tr>";
						text = text + "        <td>" + bag[i].box.id +"</td>";
						text = text + "        <td>" + bag[i].box.leadSealing + "</td>";
						text = text + "        <td>" + bag[i].goodsNum + "</td>";
						text = text + "        <td>" + bag[i].goods.pack + ":" + bag[i].goods.name + "</td>";
						text = text + "        <td>" + bag[i].goods.weight * bag[i].goodsNum + "</td>";
						text = text + "        <td>" + bag[i].goods.size * bag[i].goodsNum + "</td>";
						text = text + "    </tr>";

						totalBox = totalBox + bag[i].goodsNum;
						totalWeight = totalWeight + bag[i].goods.weight * bag[i].goodsNum;
						totalSize = totalSize + bag[i].goods.size * bag[i].goodsNum;
					}
					//集装箱数或件数统计
					text = text + "<tr><th>集装箱数或件数统计</th><td colspan='5'>" + totalBox + " " + totalWeight + " " + totalSize + "</td></tr>";
					text = text + "</table>";
					document.getElementById("show_results").innerHTML = text;
				});
			}
			//显示航线要求信息
			function show_route_request() {
				makeShipperNoteService.getAllocDetails().addCallback(function (AD) {
					console.dir(AD);
					var request1 = ['', '直达', '中转', '无要求'];
					var request2 = ['', '海运', '陆运', '陆海运', '无要求'];
					
					var routeRequest = AD.commission.routeRequest;
					var text = "";
					text = text + request1[routeRequest.direct] + ", " + request2[routeRequest.transport];
					
					document.getElementById("show_results").innerHTML = text;
				});
			}
			//显示费用信息
			function show_fee_info() {
				makeShipperNoteService.getAllocDetails().addCallback(function (AD) {
					console.dir(AD);

					var commitedService = AD.commission.commitedService;
					makeShipperNoteService.getFeeItems().addCallback(function (feeItems) {
						console.dir(feeItems);

						var fee = feeItems.list;
						makeShipperNoteService.getBoxAndGoods(document.getElementById("sn_id").value).addCallback(function (BAG) {
							console.dir(BAG);

							var bag = BAG.list;
							var weight = 0;
							for (var i in bag) {
								weight = weight + bag[i].goods.weight;
							}
							weight = weight * 1.0 / 1000;
							
							var text = "";
							text = text + "<table border='1'>";
							text = text + "    <tr><th>费用条目</th><th>费率</th><th>数量</th><th>费用</th><th>预付或到付</th></tr>";

							var rowCnt = 0;
							//一定有海运费
							for (var i in fee) {
								if (fee[i].name == "海运费") {
									text = text + "<tr><td>海运费</td><td>" + fee[i].std + fee[i].unitName + "</td><td>100海里, " + weight + "吨</td><td>" + fee[i].std * weight + "</td>";
									if (AD.commission.prePay == true) {
										text = text + "<td id='prePay'>预付</td>";
									} else {
										text = text + "<td id='prePay'>到付</td>";
									}
									text = text + "</tr>";
									rowCnt++;
									break;
								}
							}
							if (commitedService.declare == true) {				//报关费
								for (var i in fee) {
									if (fee[i].name == "报关费") {
										text = text + "<tr><td>报关费</td><td>" + fee[i].std + fee[i].unitName + "</td><td>1单</td><td>" + fee[i].std + "</td></tr>";
										rowCnt++;
										break;
									}
								}
							}
							if (commitedService.inspect == true) {				//报检费
								for (var i in fee) {
									if (fee[i].name == "报检费") {
										rowCnt++;
										break;
									}
								}
							}
							if (commitedService.insure == true) {				//保险费
								for (var i in fee) {
									if (fee[i].name == "保险费") {
										rowCnt++;
										break;
									}
								}
							}
							if (commitedService.store == true) {				//仓储费
								for (var i in fee) {
									if (fee[i].name == "仓储费") {
										rowCnt++;
										break;
									}
								}
							}
							if (commitedService.trail == true) {				//拖车费
								for (var i in fee) {
									if (fee[i].name == "拖车费") {
										rowCnt++;
										break;
									}
								}
							}
							
							text = text + "</table>";
							document.getElementById("show_results").innerHTML = text;
							document.getElementById("prePay").rowSpan = rowCnt;
						});
					});
				});
			}
			//备注
			function show_comments() {
				var text = "<textarea id='sn_comments' rows='8' cols='64'></textarea>";
				document.getElementById("show_results").innerHTML = text;
			}
		</script>
		
		<title>缮制十联单</title>
	</head>

	<body>
		<!-- 导航菜单 -->
		<div id="navigation_menu" class="nav"></div>
		<div class="content">
			<h1>缮制十联单</h1>
					
			<!-- 十联单明细 -->
			<div id="sn_details">
				<h4><a id="sn_num1"></a>号十联单明细</h4>
				<hr/>
				<table>
					<tr>
						<th>上次更改日期:</th><td id="sn_last_modified_date"></td>
						<th>第<a id="sn_num2"></a>号</th><td></td>
						<th>单据类型：</th><td><select><option>初始化单据</option></select></td>
					</tr>
				</table>
				<fieldset>
					<table>
						<tr><th>*初始化日期：</th><td><input type="text" id="sn_init_date"></td><th>*十联单编码：</th><td><input type="text" id="sn_id"></td><th>*联数：</th><td><input type="text" value="第一联"></td></tr>
						<tr><th>B/L NO.：</th><td><input type="text" id="bl_id"></td><th>TO：</th><td><input type="text" id="shipcom_name"></td><th>FROM：</th><td><input type="text" value="哈工大货代"></td></tr>
						<tr><th>发货人：</th><td><input type="text" id="sender"></td><th>收货人：</th><td><input type="text" id="receiver"></td><th>代理：</th><td><input type="text" value="哈工大货代"></td></tr>
						<tr><th>船名：</th><td><input type="text" id="ship_name"></td><th>船次：</th><td><input type="text" id="ship_schedule"></td><th>装货港：</th><td><input type="text" id="departure"></td></tr><!-- 装货港即启运港 -->
						<tr><th>前程运输：</th><td><input type="text" value=""></td><th>收货地点：</th><td><input type="text" id="receive_loc"></td></tr>
						<tr><th>卸货港：</th><td><input type="text" id="unload_loc"></td><th>目的港：</th><td><input type="text" id="destination"></td><th>交货地点：</th><td><input type="text" value=""></td></tr><!-- 卸货港即目的港 -->
						<tr><th>集装箱数：</th><td><input type="text" id="box_total"></td><th>货物种类：</th><td><input type="text" id="goods_type"></td><th>冷藏温度：</th><td><input type="text" id="goods_temp"></td></tr>
						<tr><th>可否转船：</th><td><input type="text" id="multiship"></td><th>可否分批：</th><td><input type="text" id="multischedule"></td><th>装期：</th><td><input type="text" value=""></td></tr>
						<tr><th>有效期：</th><td><input type="text" id="sn_date_of_expiry"></td><th>装箱场站(ID)：</th><td><input type="text" id="cy_id"></td></tr>
						<tr><th>审批状态：</th><td>处理中</td><th>审批流程：</th><td>缮制第一联</td></tr>
					</table>
				</fieldset>
				<div><a href="#" onClick="make_shipper_note()">制单</a> <a href="#" onClick="close_shipper_note()">关闭</a> <a href="#" onClick="go_back()">返回</a></div>
			</div>
			
			<!-- 相关信息 -->
			<div id="associate_details">
				<div>
					<table width="760">
						<tr>
							<td align="left">
								<a href="#" onClick="show_sender_info()">发货人信息</a>
								<a href="#" onClick="show_receiver_info()">收货人信息</a>
								<a href="#" onClick="show_notifier_info()">通知人信息</a>
								<a href="#" onClick="show_goods_info()">货物信息</a>
								<a href="#" onClick="show_route_request()">航线要求</a>
								<a href="#" onClick="show_fee_info()">费用信息</a>
								<!-- <a href="#" onClick="show_comm_info()">委托信息</a> -->
								<a href="#" onClick="show_comments()">备注</a>
							</td>
						</tr>
					</table>
				</div>
				<div id="show_results"></div>
			</div>
		</div>
	</body>
</html>
